<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/jquery.js"></script>
</head>
<body>
    <form action="#">
        <p>
            用户名: <input type="text">
        <span>
            字母开头，允许5-16字节，允许字母数字下划线
        </span>
        </p>
        <p>
            密码: <input type="password">
            <span>
                以字母开头，长度在6~18之间，只能包含字母、数字和下划线
            </span>
        </p>
        <script>
            let rule_obj={
                "text" :/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/,
                "password" :/^[a-zA-Z]\w{5,17}$/
            }
            let arr2=[]
            $("input").blur(function(){
                let type=$(this).prop("type")
                let inp_val= $(this).val()
                let rule1=rule_obj[type]
                let bool1=rule1.text(inp_val)
                if(bool1){
                    $(this).next().text("正确")
                }else{
                    $(this).next().text("错误")
                }

            })
        </script>
    </form>
</body>
</html>